package com.soundnet.androidhelper.ui.activity;

import android.os.Bundle;


import com.suntech.rsmit.RSMIT2;

import java.util.HashMap;

/**
 * 接受声波基类
 * lanstar 2016-03-28
 */

public abstract class SoundBaseActivity extends BaseActivity {

    //接收声波
    private RSMIT2 mRsmit2;
    //当前线程
    private Thread recordThread;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    public void MIT2Receive() {
        recordThread = new Thread(new Runnable() {
            @Override
            public void run() {
                mRsmit2 = new RSMIT2(SoundBaseActivity.this);
                HashMap<String, String> result = mRsmit2.receive();
                MIT2ReceiveComplete(result);

            }
        });
        recordThread.start();
    }

    public void MIT2Stop() {
        if (mRsmit2 != null) {
            mRsmit2.interruptReceive();
            if( recordThread != null )
            {
                try {
                    recordThread.interrupt();
                    recordThread.join();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }

    //声波接受完成后通知子类
    public abstract void MIT2ReceiveComplete(HashMap<String, String> result);
}
